package com.ts.api.http.infoflow.biz;

import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.base.ChooseEq;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.util.random.RandomUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.ts.api.module.api.convert.core.annotation.ApiReceive;
import com.ts.api.module.api.convert.core.annotation.ApiReceiveConvertType;
import com.ts.api.module.api.convert.infoflow.handler.ApiInfoFlowConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;
import com.ts.api.module.api.entity.vo.ReqGuangDianTongVO;

/**
 *  账号id-52924729
 *  @author caoxin
 */
@ApiReceive(apiClientId = "1985837888763219968", type = ApiReceiveConvertType.API_INFO_FLOW)
public class ApiInfoFlowTc52924729 implements ApiInfoFlowConvertHandler {

    @Override
    public ApiUserRequest convert(ReqGuangDianTongVO gdtVO) throws Exception {
        ApiUserRequest apiUserRequest = new ApiUserRequest();
        //  表单流程
        JSONObject bundle = JsonUtils.get(gdtVO.getBundle());
        //  年龄
        apiUserRequest.setAge(gdtVO.getAge());
        //  如果年龄为空，则设置一个22~55的随机年龄
        if(ValidParam.isEmpty(gdtVO.getAge())) {
            String randomAge = String.valueOf(RandomUtils.randomInt(22, 55));
            apiUserRequest.setAge(randomAge);
        }
        //  姓名
        apiUserRequest.setUserName(gdtVO.getUserName());
        //  电话号码
        apiUserRequest.setPhone(gdtVO.getPhone());
        //  设置城市
        apiUserRequest.setCity(gdtVO.getConvertAreaName());
        apiUserRequest.setAreaCode(gdtVO.getConvertAreaCode());

        //  性别转换
        ChooseEq.create(gdtVO.getSex())
            .when("GENDER_TYPE_UNKNOWN", () -> apiUserRequest.setSex("2"))
            .when("GENDER_TYPE_FEMALE", () -> apiUserRequest.setSex("1"))
            .when("GENDER_TYPE_MALE", () -> apiUserRequest.setSex("0"))
        .end();

        // loanAmount 贷款金额
        // 1 3万以下
        // 2 5万-10万
        // 3 10万-20万
        // 4 20万以上
        String loanAmount = bundle.getString("您的借款金额");
        ChooseEq.create(loanAmount)
            .when("3-5万", () -> apiUserRequest.setLoanAmount("1"))
            .when("5-10万", () -> apiUserRequest.setLoanAmount("2"))
            .when("10-15万", () -> apiUserRequest.setLoanAmount("3"))
            .when("15-20万", () -> apiUserRequest.setLoanAmount("3"))
            .end();

        String asset = bundle.getString("您的资产信息");
        ChooseEq.create(asset)
        .when("我有公积金", () -> apiUserRequest.setProvidentFund("4"))
        .when("我有房产", () -> apiUserRequest.setRealEstateInfo("4"))
        .when("我有车", () -> apiUserRequest.setCarInfo("4"))
        .when("我有企业", () -> apiUserRequest.setCareer("3"))
        .end();

        // sesameCredit 芝麻分
        // 1 600分以下
        // 2 600~649分
        // 3 650~699分
        // 4 700分以上
        String sesameCredit = bundle.getString("您的芝麻信用分");
        ChooseEq.create(sesameCredit)
        .when("600-650", () -> apiUserRequest.setSesameCredit("2"))
        .when("650-700", () -> apiUserRequest.setSesameCredit("3"))
        .when("700以上", () -> apiUserRequest.setSesameCredit("4"))
        .end();

        return apiUserRequest;
    }
}
